package com.wondertek.poms.dao.repo;

import com.wondertek.poms.dao.po.ProductInfoPackage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


/**
 * <p><b>IProductInfoPackageDao Description:</b> 二级产品信息 Dao 执行二级产品信息 的查询、修改、新增、删除操作</p>
 * <p>@author 窦再兴</p>
 * <p><b>DATE</b> 2020-10-19 15:14:14</p>
 */
public interface IProductInfoPackageDao extends JpaRepository<ProductInfoPackage, Long> {

    List<ProductInfoPackage> findAllByType(String type);

    /** 查询所有在用的二级产品
     *@author gaozhengxing gaozhenghang@wondertek.com.cn
     *@date 2020/12/29 14:42
     *@return  二级产品列表*/
    @Query(value = "select * from product_info_package where status=1 and system_flag=2 or system_flag is null", nativeQuery = true)
    List<ProductInfoPackage> findAllProductInfoPackage();

    /** 查询所有在用的二级产品
     *@author gaozhengxing gaozhenghang@wondertek.com.cn
     *@date 2020/12/29 14:42
     *@param  firstProductInfoPackageId 二级产品id
     *@return  二级产品列表*/
    @Query(value = "select * from product_info_package where first_product_info_package_id = ?1 and (system_flag=2 or system_flag is null)", nativeQuery = true)
    List<ProductInfoPackage> findPrdInfoPackageByFirstPrd(Long firstProductInfoPackageId);

    /** 查询poms的二级产品 权限使用
     *@author gaozhengxing gaozhenghang@wondertek.com.cn
     *@date 2020/12/23 21:19
     *@return  二级产品*/
    @Query(value = "select * from product_info_package where system_flag=2 or system_flag is null", nativeQuery = true)
    List<ProductInfoPackage> getAllPomsProductInfoPackage();

    /** 根据商品包id查询poms的有效的二级产品
     *@author gaozhengxing gaozhenghang@wondertek.com.cn
     *@date 2020/12/23 21:19
     *@return  二级产品*/
    @Query(value = "select pp.* from  PRD_INFO pi left join product_info_package pp on pi.PRODUCT_INFO_PACKAGE_ID=pp.PRODUCT_INFO_PACKAGE_ID  " +
            "where pi.PRDINFOID=?1 and (pp.system_flag=2 or pp.system_flag is null) and (pi.system_flag=2 or pi.system_flag is null)", nativeQuery = true)
    ProductInfoPackage getValidProductInfoPackage(Long prdInfoId);

}
